/// <reference path="../../wx/ad/WxVideoAd.ts" />
namespace mplat {
    export class OppoVideoAd extends WxVideoAd {

        protected _videoAd: any;

        protected _getVideoAd(id?: string) {
            if (!this._videoAd) {
                this._videoAd = qg.createRewardedVideoAd({
                    adUnitId: id || this._info.ids[0]
                });
                this._videoAd.onError(this._onVideoErr.bind(this))
                this._videoAd.onLoad(this._onVideoLoaded.bind(this))
                this._videoAd.onClose(this._onVideoClose.bind(this))
            }
            return this._videoAd;
        }

        protected _canUseVideo(){
            return !!qg.createRewardedVideoAd
        }
        protected _createdAd() {
            if (!this._videoAd) return;
            this.loadVideoAd();
        }

        protected _videoPlay() {
            this._videoAd.show().then(() => {

            }).catch(err => {
                this.loadVideoAd()
            })

            debugLog('激励视频开始播放')
            if (!!this._info.startPlay) this._info.startPlay();
            this._readyPlayVideo = false;
        }

        protected _onVideoClose(res) {
            super._onVideoClose(res);
            this.loadVideoAd();
        }
    }
}